// Title : Add questions Java script 
// Author : harjeet
// Last chance : 7-10-2012


var questionno=0;


function addquestion(type)
{

	//alert(type);

	switch (type)
		{
		case 'onechoice' : onechoice(); break;
		case 'detail'	 : detailque(); break;
		case 'yesno'	 : yesnoque(); break;
		case 'chkbox'    : checkbox();break;		
		}
}



function onechoice()
	{
		
		addquestionheadder();	
		addoptions();

}

function detailque()
{

	addquestionheadder();
	adddetail();
}

function yesnoque()
{
	addquestionheadder();
	addyesno();
}

function checkbox()
{
	addquestionheadder();
	addoptions();
	
}



function addquestionheadder()
{
questionno++;
var quediv=document.getElementById("survey_questions");
quediv.innerHTML+="<div id='divqueno"+ questionno+"'><b>Question no : " + questionno + "</b><br/>Question :  <input type='text' class='input-xxlarge'/> <br/> </div>";


}



function addoptions()
{
	//alert(this.questionno);
	var quedivq=document.getElementById("survey_questions");
	
	  quedivq.innerHTML+="<div id='divqueno" +this.questionno + "ans'> " +
	  "Op 1 : <input type='text' class='inputlarge'/><br/>" +
	  "Op 2 : <input type='text' class='inputlarge'/><br/>" +
	  "Op 3 : <input type='text' class='inputlarge'/><br/>" +
	  "Op 4 : <input type='text' class='inputlarge'/><br/>" +
	  "<input type='button' value='Save' class='btn btn-success'>&nbsp;<input type='button' value='Cancel' onclick='cancel(divqueno"+this.questionno+");' class='btn btn-danger'><br/><hr/></div>";
	  

	  
	
}

function adddetail()
{
	var quedivq=document.getElementById("survey_questions");
	  quedivq.innerHTML+="<div id='divqueno" +this.questionno + "ans'> " +
	  "<b><i>Descriptive answer</b></i><br/>" +
	"<input type='button' value='Save' class='btn btn-success'>&nbsp;<input type='button' value='Cancel' onclick='cancel(divqueno"+this.questionno+");' class='btn btn-danger'><br/><hr/></div>";
	
}

function addyesno()
{
	var quedivq=document.getElementById("survey_questions");
	  quedivq.innerHTML+="<div id='divqueno" +this.questionno + "ans'> " +
	  "<b><i>Options : Yes-no </b></i><br/>" +
	"<input type='button' value='Save' class='btn btn-success'>&nbsp;<input type='button' value='Cancel' onclick='cancel(divqueno"+this.questionno+");' class='btn btn-danger'><br/><hr/></div>";
	
	
}

function cancel(divid)
{
	
	divid.innerHTML=" ";
	var ansdiv=divid.id + "ans";		
	document.getElementById(ansdiv).innerHTML=" ";

}
